<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<link rel="stylesheet" type="text/css" href="../../css/mui.min.css" />
		<script src="../../js/mui.min.js" type="text/javascript" charset="utf-8"></script>
		<style>
			.main_content p {
				font-size: 1em;
				color: black;
				text-indent: 2em;
				padding: 6px;
			}
			.main_content img {
				padding: 8px;
			}
			.sub_header {
				text-align: center;
				background-color: rgba(0, 188, 0, 0.7);
				height: 36px;
				margin-top: 8px;
				margin-bottom: 8px;
			}
			.sub_header h3 {
				color: white;
				position: relative;
				top: 20%;
				transform: translateY(-50%);
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">Java 基础</h1>
		</header>
		<div class="mui-content">
			<div class="mui-content-padded" style="margin: 5px;">
				<div class="sub_header">
					<h3>流程控制</h3>
				</div>
				<div class="main_content">
					<p>分支流程控制理解起来较简单，如下所示：
						<br /> [code=java]
						<br /> #[Tags]/**
						<br /> &nbsp;#[Tags]* if... else ... 一杯以上，第二杯半价
						<br /> &nbsp;#[Tags]*/
						<br /> #[Keywords]public #[Keywords]class #IfStarementDemo {
						<br /> &nbsp;&nbsp; &nbsp;#[Keywords]public #[Keywords]static #[Keywords]void #main(String[] args) {
						<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;#[Keywords]if #(10 &gt; 20) {
						<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;#System.#[Fields]out#.println(#[Fields]&quot;-_-!&quot;#);
						<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;#} #[Keywords]else #{
						<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;#System.#[Fields]out#.println(#[Fields]&quot;*_*&quot;#);
						<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;#}
						<br /> &nbsp;&nbsp; &nbsp;#}
						<br /> #}
						<br /> [/code]
						<br /> 如下案例实现一个简单的业务逻辑： 从控制台输入一个数，如果大于0输出&quot;正整数&quot;，如果小于0输出&quot;负整数&quot;，如果等于0输出&quot;零&quot;。
						<br /> [code=java]
						<br /> #[Keywords]import #java.util.Scanner;
						<br /> #[Tags]/**
						<br /> &nbsp;#[Tags]* if... else ... 一杯以上，第二杯半价
						<br /> &nbsp;#[Tags]*/
						<br /> #[Keywords]public #[Keywords]class #IfStarementDemo2 {
						<br /> &nbsp;&nbsp; &nbsp;#[Keywords]public #[Keywords]static #[Keywords]void #main(String[] args) {
						<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;#Scanner s = #[Keywords]new #Scanner(System.in);
						<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;#[Keywords]int #a = s.nextInt();
						<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;#[Keywords]if #(a &gt; 0) {
						<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;#System.#[Fields]out#.println(#[Fields]&quot;正整数&quot;#);
						<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;#} #[Keywords]else #[Keywords]if #(a &lt; 0) {
						<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;#System.#[Fields]out#.println(#[Fields]&quot;负整数&quot;#);
						<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;#} #[Keywords]else #{
						<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;#System.#[Fields]out#.println(#[Fields]&quot;零&quot;#);
						<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;#}
						<br /> &nbsp;&nbsp; &nbsp;#}
						<br /> #}
						<br /> [/code]
						<br /> 如下用分支流程控制实现买饮料的业务，&quot;0杯不卖，1杯以上，第二杯半价&quot;，如下：
						<br /> [code=java]
						<br /> #[Keywords]import #java.util.Scanner;
						<br /> #[Tags]/**
						<br /> &nbsp;#[Tags]* if... else ... 一杯以上，第二杯半价
						<br /> &nbsp;#[Tags]*/
						<br /> #[Keywords]public #[Keywords]class #IfStarementDemo3 {
						<br /> &nbsp;&nbsp; &nbsp;#[Keywords]public #[Keywords]static #[Keywords]void #main(String[] args) {
						<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;#Scanner console = #[Keywords]new #Scanner(System.in);
						<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;#System.#[Fields]out#.println(#[Fields]&quot;请输入购买数量：&quot;#);
						<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;#[Keywords]int #qty = console.nextInt();
						<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;#[Keywords]double #price = 6.00;
						<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;#[Keywords]double #pay = 6.00;
						<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;#[Keywords]if #(qty &lt; 1) {
						<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;#System.#[Fields]out#.println(#[Fields]&quot;不卖!&quot;#);
						<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;#[Keywords]return#;#
						<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;#}
						<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;#[Keywords]if #(qty &gt; 1) {
						<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;#pay += (qty - 1) * price / 2;
						<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;#}&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;
						<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;#System.#[Fields]out#.println(#[Fields]&quot;支付金额：&quot;# &nbsp;+ pay);
						<br /> &nbsp;&nbsp; &nbsp;#}
						<br /> #}
						<br /> [/code]
						<br /> 注：&quot;+=&quot;是一种简写方式，如下所示：
						<br /> [code=java]
						<br /> #[Tags]/**
						<br /> &nbsp;#[Tags]* if... else ... 一杯以上，第二杯半价
						<br /> &nbsp;#[Tags]*/
						<br /> #[Keywords]public #[Keywords]class #IfStarementDemo4 {
						<br /> &nbsp;&nbsp; &nbsp;#[Keywords]public #[Keywords]static #[Keywords]void #main(String[] args) {
						<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;#[Keywords]int #a = 100;
						<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;#a += a + 1;
						<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;#System.#[Fields]out#.println(a);
						<br /> &nbsp;&nbsp; &nbsp;#}
						<br /> #}
						<br /> [/code]
						<br /> 如下，我们再演示一个银行利率业务的例子：
						<br /> [code=java]
						<br /> #[Tags]/**
						<br /> &nbsp;#[Tags]* if... else ... 嵌套演示：银行利率计算
						<br /> &nbsp;#[Tags]*/
						<br /> #[Keywords]public #[Keywords]class #IfElseDemo {
						<br /> &nbsp;&nbsp; &nbsp;#[Keywords]public #[Keywords]static #[Keywords]void #main(String[] args) {
						<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;#[Keywords]double #base = 7.7 / 100; #[Comments]// 基本年利率
						<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;#[Keywords]int #years = 5; #[Comments]// 贷款年限
						<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;#[Keywords]double #rate = base; #[Comments]// 实际利率
						<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;#[Keywords]if #(years &lt;= 1) {
						<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;#rate *= 0.5;
						<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;#} #[Keywords]else #[Keywords]if #(years &lt;= 3) { #[Comments]// 如果三年以内
						<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;#rate *= 0.7; #[Comments]// 七折
						<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;#} #[Keywords]else #[Keywords]if #(years &lt;= 5) {#[Comments]// 如果五年以内
						<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;#rate = base;#[Comments]// 原价
						<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;#} #[Keywords]else #{#[Comments]// 如果五年以上
						<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;#rate = 1.1;#[Comments]// 1.1倍
						<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;#}
						<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;#System.#[Fields]out#.println(#[Fields]&quot;实际利率(%)：&quot;# + rate);
						<br /> &nbsp;&nbsp; &nbsp;#}
						<br /> #}
						<br /> [/code]
					</p>

				</div>
			</div>
		</div>

	</body>

</html>